const tree = {
    val:"a",
    children:[
        {
            val: "b",
            children: [
                {
                    val:"d",
                    children:[]
                },
                {
                    val:"e",
                    children:[]
                }
            ]
        },
        {
            val: "c",
            children: [
                {
                    val:"f",
                    children:[]
                },
                {
                    val:"g",
                    children:[]
                }
            ]
        }
    ]
};

/**
 * @description 广度优先遍历算法
 * @description 传入根节点，将根节点入队，取出队头元素，输出该元素的值，并将该元素的所有子节点依次入队
 * @param root
 */
const bfs = (root) => {
    const q = [root];
    while(q.length > 0){
        const n = q.shift();
        console.log(q.val);
        n.children.forEach(chile => {
            q.push(child);
        })
    }
};

bfs(tree);